<template>
    <div>
        <div class="nav-bar">
            <div class="bottom">
                <span>
                    <van-icon @click="$router.push('/replace/mybalance')" class="go-back" name="arrow-left" />
                </span>
                <span>提现</span>
            </div>
        </div>
        <div class="user_withdraw">
            <div>
                <span class="plzsend">请输入提现金额</span>
                <van-icon  class="add_blance"  @click="$router.push('/replace/addAccount')" name="plus" />
            </div>
            <div class="sendinput">
                ￥<input type="text" :placeholder="'可提现余额NAN元'" v-model="money">
            </div>
            <div class="seluser" v-for="(item,index) in payList" :key="index">
                <span class="outside" @click="selTxAccount(item,index)"><span :class="['inside',checkIndex==index?'ischcek':'']"></span></span>
                <span class="usermsg" @click="selTxAccount(item,index)">
                    {{item.account_type==1?'支付宝':'银行卡' + `账户`}}
                    {{item.account | num}}
                    {{`(${item.account_name})`}}
                </span>
                <span class="default" v-if="item.is_default==1">默认</span>
                <van-icon @click="$router.push('/replace/withaccount')" name="arrow" class="rightjiantou" />
            </div>
            <div class="rule">
                首次提现金额为20元，最小单次提现金额为200元，每月可提现2次（提现金额均为税前金额）
            </div>
        </div>
        <div class="balance_btn" @click="withdraw" style="background:#ddd">
          提现正在开发中，暂不开放
        </div>
    </div>
</template>
<script>
import {getWithdrawal,appliWithdrawal} from '@/api/withdrawal'
import {Toast} from 'vant'
export default {
    data(){
        return {
            checkIndex:0,
            payList:[],
            selData:{},
            money:""
        }
    },
    computed:{
        coin(){
            return this.$store.state.user.canUserCoin
        }
    },
    methods:{
        selTxAccount(item,index){
            this.checkIndex=index
            this.selData = item
        },
        getAccountList(){
            getWithdrawal().then(res=>{
                this.payList = res.data
                this.payList.forEach((item,index)=>{
                    if(item.is_default==1){
                        this.checkIndex = index
                        return
                    }
                })
                this.selData = this.payList[this.checkIndex]
            })
        },
        withdraw(){
            // if (this.payList.length == 0) {
            //     Toast.fail('请先添加提现账户')
            //     return
            // }
            // if (parseInt(this.money)>parseInt(this.coin)) {
            //     Toast.fail('余额不足')
            //     return
            // }
            // if (this.money == "") {
            //     Toast.fail('请输入提现金额')
            //     return
            // }
            // if (this.money <= "0") {
            //     Toast.fail('请输入正确的提现金额！')
            //     return
            // }
              Toast.fail('该功能开发中，暂不开放！')
            // 暂不开放
            // let params = {
            //     price:this.money,
            //     withdrawal_id:this.selData.id
            // }
            // appliWithdrawal(params).then(res=>{
            //     if (res.code==200) {
            //         this.$store.state.user.canUserCoin-=this.money
            //         Toast.success('提现申请成功,请等待管理员审核')
            //     }
            // })
        }
    },
    deactivated() {
        this.$destroy(true); //销毁组件
    },
    created(){
        this.getAccountList()
    },
    filters:{
        num(value){
            return value.slice(0,3) + '****' + value.slice(-3)
        }
    }
}
</script>
<style lang="less" scoped>
.nav-bar {
    width: 100%;
    background-color: #fff;
    margin-bottom: 20px;
    position: relative;
    z-index: 5000;
    .bottom {
        padding: 0 .4rem;
        box-sizing: border-box;
        line-height: 1.333333rem;
        font-size: 20px;
        z-index: 1;
        text-align: center;
        >span {
            &:nth-child(1) {
                height: 1.333333rem;
                float: left;
                text-align: center;
                font-weight: 700;
                i{
                    line-height: 1.333333rem;
                }
            }
            &:nth-child(2) {
                text-align: center;
                font-weight: 700;
            }
        }
    }
}
.user_withdraw{
    padding:0 11.5px 0 12.5px;
    .plzsend{
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 600;
        color: #353535;
    }
    .add_blance{
        float: right;
        margin-right: 5px;
        color: #006CFF;
        vertical-align: middle;
        font-size: 20px;
    }
    .sendinput{
        height: 42px;
        font-size: 20px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #353535;
        margin-top: 10px;
        input{
            height: 42px;
            width: 70%;
            font-size: 15px;
            border: none;
            outline: none;
            padding-left: 5px;
        }
    }
    .seluser{
        margin-top: 15px;
        line-height: 21px;
        .outside{
            vertical-align: middle;
            box-sizing: content-box;
            display: inline-block;
            width: 14px;
            height: 14px;
            border-radius: 50%;
            border: 1px #006CFF solid;
            margin-right: 10px;
        }
        .inside{
            box-sizing: content-box;
            display: block;
            margin: 4px 4px;
            width: 6px;
            height: 6px;
            border-radius: 50%;
        }
        .usermsg{
            vertical-align: middle;
            font-size: 14px;
            font-family: PingFang-SC-Regular, PingFang-SC;
            font-weight: 400;
            color: #353535;
        }
        .rightjiantou{
            vertical-align: middle;
            float: right;
            color: #979797;
            line-height:21px ;
        }
    }
    
    .ischcek{
        background: #006CFF;
    }
    .default{
        color: #006CFF;
        font-size: 12px;
        font-family: PingFang-SC-Regular, PingFang-SC;
        font-weight: 400;
        margin-left: 10px;
        vertical-align: middle;
    }
    
    .rule{
        margin-top: 28px;
        font-size: 11px;
        font-family: PingFang-SC-Regular, PingFang-SC;
        font-weight: 400;
        color: #0067FF;
    }
}
.balance_btn{
    width: 325px;
    height: 45px;
    line-height: 45px;
    font-size: 20px;
    font-family: PingFang-SC-Medium, PingFang-SC;
    font-weight: 500;
    color: #FFFFFF;
    background: #0016FF;
    border-radius: 22.5px;
    text-align: center;
    position: absolute;
    bottom: 25px;
    left: calc(~'50% - 162.5px')
}
</style>